package com.gsafety.libraryktx.expand

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import com.gsafety.library.LifeCycle.ObserverNoneNull

/**
 * LiveData的改变事件，回调中不可能为null
 */
inline fun <T> LiveData<T>.observerNotNull(
        owner: LifecycleOwner,
        crossinline block: (data: T) -> Unit
)
{
    this.observe(owner, object : ObserverNoneNull<T>()
    {
        override fun changed(data: T)
        {
            block.invoke(data)
        }
    })
}